#!/usr/bin/env python

# -*- coding: utf-8 -*-
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *


class TextWindow(QWidget):
    def __init__(self, *args, **kwargs):
        super(TextWindow, self).__init__(*args, **kwargs)
        #获取显示器分辨率大小
        self.desktop = QApplication.desktop()
        self.screenRect = self.desktop.screenGeometry()
        self.height = self.screenRect.height()
        self.width = self.screenRect.width()
        self.rate = self.height*1.0/1080
        self.setObjectName("root")
        self.setFixedSize(int(640*self.rate),int(320*self.rate))
        #保持始终在顶部开始显示
        #self.setWindowFlag(Qt.WindowStaysOnTopHint)
        self.setWindowFlag(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        layout = QVBoxLayout(self)
        self.bgframe = QFrame(self)
        self.bgframe.setObjectName("bgframe")
        layout.addWidget(self.bgframe)
        frlayout = QVBoxLayout(self.bgframe)
        self.label = QLabel(self)
        self.label.setWordWrap(True)
        self.label.setObjectName("label")
        frlayout.addWidget(self.label)
        #frlayout.addWidget(QPushButton(
            #"退出整个程序", self, clicked=self.onQuit))
        pl = self.label.palette()
        pl.setBrush(QPalette.Base,QBrush(QColor(255,0,0,0)))
        self.label.setPalette(pl)
        self.setStyleSheet("QWidget#root{padding:0px;}"
        "QFrame#bgframe{background:#CF000000;border-radius:%ipx;border:%ipx solid #AFAFAF;}"
        "QLabel#label{border:0px;background:transparent;font-family: \"微软雅黑\";font-weight:bold;font-size:%ipx;color:#ffffff;}"%(4*self.rate,self.rate,20*self.rate))

    def mousePressEvent(self, e):
        #print("hide")
        self.hide()

    def setText(self,text):
        self.label.setText(text)

textwindow = None
def showText(text):
    global textwindow
    if textwindow == None:
        textwindow = TextWindow()
    print("开始界面显示")
    textwindow.setText(text)
    textwindow.show()
